package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.PmsProductAttribute;
import com.itheima.mapper.PmsProductAttributeMapper;
import com.itheima.service.db.PmsProductAttributeService;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;

@DubboService
public class PmsProductAttributeServiceImpl implements PmsProductAttributeService {
    @Autowired
    PmsProductAttributeMapper ppaMapper;

    @Override
    public List<PmsProductAttribute> findByPpacId(Long id) {
        LambdaQueryWrapper<PmsProductAttribute> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PmsProductAttribute::getProductAttributeCategoryId, id);
        return ppaMapper.selectList(lqw);
    }

    @Override
    public List<PmsProductAttribute> findByIds(List<Long> ids) {
        return ppaMapper.selectBatchIds(ids);
    }

    @Override
    public PageBeanVo findByTtpe(Long cid, Integer type, Integer pageNum, Integer pageSize) {
        Page<PmsProductAttribute> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<PmsProductAttribute> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PmsProductAttribute::getProductAttributeCategoryId, cid).eq(PmsProductAttribute::getType, type);
        Page<PmsProductAttribute> ppaPage = ppaMapper.selectPage(page, lqw);
        return new PageBeanVo(pageNum, pageSize, ppaPage.getTotal(), ppaPage.getRecords());
    }

    @Override
    public void save(PmsProductAttribute pmsProductAttribute) {
        ppaMapper.insert(pmsProductAttribute);
    }

    @Override
    public void deleteByIds(Long[] ids) {
        ppaMapper.deleteBatchIds(Arrays.asList(ids));
    }

    @Override
    public PmsProductAttribute findById(Long id) {
        return ppaMapper.selectById(id);
    }

    @Override
    public void update(PmsProductAttribute pmsProductAttribute) {
        ppaMapper.updateById(pmsProductAttribute);
    }

}
